/**
 *  Copyright (C) 2010:
 *                 Buzzanca Marco <marco.bzn@gmail.com>
 *         Monaco Davide Giuseppe <black.ralkass@gmail.com>
 *              Petralia Veronica <veronicapetralia@gmail.com>
 *
 * This file is part of DS2011BMP
 *
 * DS2011BMP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * DS2011BMP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/** 
 * @file workflow.h
 * @author Davide Giuseppe Monaco
 *
 * This header file contains Workflow class declaration.
 */

#ifndef _WORKFLOW_H_
#define _WORKFLOW_H_ 1

#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <vector>

#include "taskdescriptor.h"

/**
 * @brief Workflow class represents a set of tasks that some UI submits
 * to the distributed system.
 *
 * More in detail a Workflow is a container of TaskDescriptor identified by an ID.
 */
class Workflow
{
	private:
    
    // enables boost serialization access
    friend class boost::serialization::access;
    
    /**
     * @brief Serialization member function.
     *
     * boost::serialization needs it.
     */
    template <class Archive>
    void serialize(Archive& ar, const unsigned int version)
    {
      ar & BOOST_SERIALIZATION_NVP(_tasks);
      ar & _ID;
    }

    /**
     * @brief The TaskDescriptor container.
     */
		std::vector<TaskDescriptor> _tasks;
    
    /**
     * @brief Current Workflow ID.
     */
		int _ID;

	public:
    /**
     * @brief Default Constructor.
     *
     * @note after using this constructor _ID must be set manually.
     */
		Workflow(void);

    /**
     * @brief Constructor specifying current Workflow ID.
     * @param id  current Workflow ID.
     */
		Workflow(int id);

    /**
     * @brief Destructor.
     */
		~Workflow(void);
		
    /**
     * @brief Return a reference to TaskDescriptor container.
     * @return a reference to TaskDescriptor container.
     */
    const std::vector<TaskDescriptor>& getTasks(void) const;

    /**
     * @brief Set current TaskDescriptor container.
     * @param val   current TaskDescriptor container.
     */
		void setTasks(const std::vector<TaskDescriptor>& val);

    /**
     * @brief Access the element at the position index in the container.
     * @param index   the position in the container of the element we desire.
     * @return        a constant reference to the element at the position index.
     */
		const TaskDescriptor& getTask(int index) const;

    /**
     * @brief Insert a TaskDescriptor in the container.
     * 
     * No position are specified, so it will be pushed back.
     *
     * @param ts    the TaskDescriptor we want to add.
     */
		int addTask(const TaskDescriptor& ts);

    /**
     * @brief Returns current Workflow id.
     * @return current Workflow id.
     */
		int getID(void) const;

    /**
     * Set current Workflow id.
     * @param val   current Workflow id.
     */
		void setID(int val);

    /**
     * @brief Returns container size.
     * @return container size.
     */
    size_t size(void) const;

    friend std::ostream& operator << (std::ostream& os, const Workflow& wf);
};

#endif /* _WORKFLOW_H_ */
